package string;

public class StringBuilderDemo {
    public static void main(String[] args) {
       // StringBuilder的创建方式;
        StringBuilder builder1=new StringBuilder();//空字符串
        StringBuilder builder2=new StringBuilder("abc");//abc串

       //String 和StringBuilder互转：
        String str="abc";
        StringBuilder builder3=new StringBuilder(str);//abc串
        String str2=builder3.toString();



        //复制ard的内容到builder中----好好学习java
        String ard="好好学习java";
        StringBuilder builder=new StringBuilder(ard);

        //append():追加内容----在末尾追加
        builder.append(",为了找个工作");
        System.out.println(builder);//好好学习java,为了找个工作

        //replace（）：替换部分内容（含头不含尾）
        builder.replace(9,16,"就是改变世界");
        System.out.println(builder);//好好学习java,就是改变世界

        //delete():删除部分nr（含头不含尾）
        builder.delete(0,8);//删除下标0到7的
        System.out.println(builder);//就是改变世界


        //insert（）：插入内容
        builder.insert(0,"活着");
        System.out.println(builder);//活着，就是为了改变世界








        StringBuilder builder4=new StringBuilder();
        StringBuilder builder5=new StringBuilder("wxy");

        String atr1="wxy";
        StringBuilder builder6=new StringBuilder(atr1);
        String atr2=builder6.toString();


        StringBuilder a1=new StringBuilder();
        StringBuilder a2=new StringBuilder("oop");

        String a3="oop";
        StringBuilder a4=new StringBuilder(a3);
        String a5=a4.toString();



        String q="我爱中国";
        StringBuilder a=new StringBuilder(q);

        a.append(",我骄傲");
        System.out.println(a);


        a.delete(5,9);
        System.out.println(a);

        a.replace(5,10,"我为祖国自豪");
        System.out.println(a);

        a.insert(6,"很");
        System.out.println(a);




        }
}
